package com.ciwong.epaper.modules.scan.util;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;

import com.ciwong.epaper.R;
import com.ciwong.epaper.bean.SelectObject;
import com.ciwong.epaper.modules.epaper.bean.Answer;
import com.ciwong.epaper.modules.epaper.bean.EpaperInfo;
import com.ciwong.epaper.modules.epaper.bean.Module;
import com.ciwong.epaper.modules.epaper.ui.TheHearingActivity;
import com.ciwong.epaper.modules.scan.bean.AnswerCard;
import com.ciwong.epaper.modules.scan.ui.AnswerCardActivity;
import com.ciwong.epaper.modules.scan.ui.CaptureActivity;
import com.ciwong.epaper.modules.scan.ui.EpaperQRDetailActivity;
import com.ciwong.epaper.modules.scan.ui.EpaperQRInfoActivity;
import com.ciwong.epaper.modules.scan.ui.NewTypeQrDetailActivity;
import com.ciwong.epaper.modules.scan.ui.SelectObjectDialogActivity;
import com.ciwong.epaper.util.IntentFlag;
import com.ciwong.epaper.util.download.DownLoadInfo;
import com.ciwong.mobilelib.utils.BaseJumpManager;

/**
 * 扫一扫 跳转管理类
 *
 * @author bin
 * @version ciwong v.1.0 2015/7/23 19:40
 * @since ciwong v.1.0
 */
public class ScanJumpManager extends BaseJumpManager {

    /**
     * 调整到扫一扫
     *
     * @param act    启动Activity
     * @param mode   {@link com.zxing.camera.CameraManager.CaptureMode} 扫一扫跳转类型
     * @param action CHOOSE_BRAND_TYPE_DEFAULT 跳转动作类型
     */
    public static void jumpCature(Activity act, int mode, int action) {
        Intent intent = getBaseIntent(0, act, CaptureActivity.class);
        intent.putExtra(IntentFlag.INTENT_FLAG_TYPE, mode);
        intent.putExtra(IntentFlag.INTENT_FLAG_ACTION, action);
        act.startActivity(intent);
    }

    /**
     * 跳转到扫一扫 重新提交功能
     *
     * @param act  启动Activity
     * @param mode {@link com.zxing.camera.CameraManager.CaptureMode} 扫一扫跳转类型
     */
    public static void jumpCature(Activity act, int mode, Answer answer) {
        Intent intent = getBaseIntent(0, act, CaptureActivity.class);
        intent.putExtra(IntentFlag.INTENT_FLAG_TYPE, mode);
        intent.putExtra(CaptureActivity.INTENT_FLAG_ANSWER, answer);
        act.startActivity(intent);
    }

    /**
     * 跳转到扫一扫
     *
     * @param goBackId     返回按钮的文字id
     * @param act          启动activity
     * @param downLoadInfo 文件下载对象
     * @param module       章节详细内容
     * @param position     章节详细资源下标
     * @param mode         {@link com.zxing.camera.CameraManager.CaptureMode} 扫一扫跳转类型
     */
    public static void jumpCature(int goBackId, Activity act,
                                  DownLoadInfo downLoadInfo, Module module, int position, int mode) {
        Intent intent = getBaseIntent(goBackId, act, CaptureActivity.class);
        intent.putExtra(IntentFlag.INTENT_FLAG_DOWNLOAD_INFO, downLoadInfo);
        intent.putExtra(IntentFlag.INTENT_FLAG_OBJ, module);
        intent.putExtra(IntentFlag.INTENT_FLAG_POSITION, position);
        intent.putExtra(IntentFlag.INTENT_FLAG_TYPE, mode);
        act.startActivity(intent);
    }

    public static void jumpToSelectObjectDialog(int goBackId, Activity act,
                                                int requestCode, List<SelectObject> selectObjects,
                                                SelectObject selectObject) {
        Intent intent = getBaseIntent(goBackId, act,
                SelectObjectDialogActivity.class);
        intent.putExtra(IntentFlag.INTENT_FLAG_OBJ_LIST,
                (Serializable) selectObjects);
        intent.putExtra(IntentFlag.INTENT_FLAG_OBJ, selectObject);
        act.startActivityForResult(intent, requestCode);
        act.overridePendingTransition(R.anim.down_bottom_in, 0);
    }

    /**
     * 跳转答题卡
     *
     * @param act            启动activity
     * @param answerCardList 答题卡列表
     * @param rootPath       根目录
     * @param isOutAnsewer   扫答题卡界面classId ,codeId 是被传过来 true
     */
    public static void jumpAnswerCard(Activity act,
                                      List<AnswerCard> answerCardList, String rootPath,
                                      boolean isOutAnsewer) {
        Intent in = getBaseIntent(0, act, AnswerCardActivity.class);
        in.putExtra(IntentFlag.INTENT_FLAG_PATH, rootPath);
        in.putExtra(IntentFlag.INTENT_FLAG_OBJ_LIST,
                (Serializable) answerCardList);
        in.putExtra(IntentFlag.INTENT_FLAG_ACTION, isOutAnsewer);
        act.startActivityForResult(in, 1);
    }

    /**
     * 资源
     *
     * @param goBackId
     * @param act
     * @param downLoadInfos
     * @param serverList   获取的服务列表
     * @param
     */
    public static void jumpNewspaperQRInfo(int goBackId, Activity act,
                                           ArrayList<DownLoadInfo> downLoadInfos, String key, Boolean isNoData, List<EpaperInfo.Server> serverList) {
        Intent in = getBaseIntent(goBackId, act, EpaperQRInfoActivity.class);
        in.putExtra(IntentFlag.INTENT_FLAG_OBJ, downLoadInfos);
        in.putExtra(IntentFlag.INTENT_FLAG_STR, key);
        in.putExtra(IntentFlag.INTENT_FLAG_TYPE, isNoData);
        in.putExtra(IntentFlag.INTENT_FLAG_OBJ_LIST, (Serializable) serverList);
        act.startActivity(in);
    }

    /**
     * @param goBackId
     * @param act
     * @param downLoadInfos
     * @param key
     * @param isPreView    是否是资源预览
     */
    public static void jumpNewSpagerQRInfoPreView(int goBackId, Activity act, ArrayList<DownLoadInfo> downLoadInfos, String key, boolean isPreView) {
        Intent in = getBaseIntent(goBackId, act, EpaperQRInfoActivity.class);
        in.putExtra(IntentFlag.INTENT_FLAG_OBJ, downLoadInfos);
        in.putExtra(IntentFlag.INTENT_FLAG_STR, key);
        in.putExtra(IntentFlag.INTENT_FLAG_PRE_VIEW, isPreView);
        act.startActivity(in);
    }

    /**
     *跳转到新的资源详情页
     * @param goBackId
     * @param act
     * @param downLoadInfos
     * @param isPreview
     */
    public static void jumpToNewTypeQrDetailAct(int goBackId, Activity act,
                                               List<DownLoadInfo>  downLoadInfos,boolean isPreview) {
        Intent intent = getBaseIntent(goBackId, act, NewTypeQrDetailActivity.class);

        intent.putExtra(IntentFlag.INTENT_FLAG_OBJ, (Serializable) downLoadInfos);
        intent.putExtra(IntentFlag.INTENT_FLAG_PREVIEW,isPreview);
        act.startActivity(intent);
    }

    /**
     * 资源详情
     *
     * @param goBackId
     * @param act
     * @param downLoadInfo
     */
    public static void jumpNewspaperQRDetail(int goBackId, Activity act,
                                             DownLoadInfo downLoadInfo, String key, List<EpaperInfo.Server> servers) {
        Intent in = getBaseIntent(goBackId, act, EpaperQRDetailActivity.class);
        in.putExtra(IntentFlag.INTENT_FLAG_OBJ, downLoadInfo);
        in.putExtra(IntentFlag.INTENT_FLAG_STR, key);
        in.putExtra(IntentFlag.INTENT_FLAG_OBJ_LIST, (Serializable) servers);
        act.startActivity(in);
    }

    /**
     * @param goBackId
     * @param act
     * @param downLoadInfo
     * @param key
     * @param serverList
     * @param isPreView    资源预览
     */
    public static void jumpNewspaperQRDetailPreView(int goBackId, Activity act,
                                                    DownLoadInfo downLoadInfo, String key, List<EpaperInfo.Server> serverList, boolean isPreView) {
        Intent in = getBaseIntent(goBackId, act, EpaperQRDetailActivity.class);
        in.putExtra(IntentFlag.INTENT_FLAG_OBJ, downLoadInfo);
        in.putExtra(IntentFlag.INTENT_FLAG_STR, key);
        in.putExtra(IntentFlag.INTENT_FLAG_PRE_VIEW, isPreView);
        in.putExtra(IntentFlag.INTENT_FLAG_OBJ_LIST, (Serializable) serverList);
        act.startActivity(in);
    }
}
